package io.renren.modules.zhaopin.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.modules.zhaopin.entity.BackgroundCheckOrdersEntity;
import io.renren.modules.zhaopin.entity.BackgroundCustomInfoEntity;
import io.renren.modules.zhaopin.service.BackgroundCheckOrdersService;
import io.renren.modules.zhaopin.service.BackgroundCustomInfoService;
import io.renren.modules.zhaopin.service.BackgroundItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 背调订单
 * 最初下单时的派单
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2024-03-24 16:21:36
 */
@RestController
@RequestMapping("/zhaopin/backgroundcheckorders")
public class BackgroundCheckOrdersController {
    @Autowired
    private BackgroundCheckOrdersService backgroundCheckOrdersService;

    /**
     * 获取背调项
     *  用于点击短信链接打开页面，展示用户将要提交的表单项目
     *  用户在下单时的表根据reportId查询，得到 customitemId，
     *  根据customitemId 在 background_custom_info 表查询得到多个背调项id：chooseList
     *  根据chooseList 在 background_item 表查询得到多个背调项信息
     *
     * @param reportId 根据报告id获取报告信息
     * @return
     */
    @GetMapping("/getOrderItem")
    public R getOrderItem(@RequestParam(value = "reportId", defaultValue = "") String reportId) {

        R r = backgroundCheckOrdersService.getOrderItem(reportId);
        return R.ok().put("data", r);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:backgroundcheckorders:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = backgroundCheckOrdersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:backgroundcheckorders:info")
    public R info(@PathVariable("id") Long id) {
        BackgroundCheckOrdersEntity backgroundCheckOrders = backgroundCheckOrdersService.getById(id);

        return R.ok().put("backgroundCheckOrders", backgroundCheckOrders);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BackgroundCheckOrdersEntity backgroundCheckOrders) {
        backgroundCheckOrdersService.save(backgroundCheckOrders);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:backgroundcheckorders:update")
    public R update(@RequestBody BackgroundCheckOrdersEntity backgroundCheckOrders) {
        backgroundCheckOrdersService.updateById(backgroundCheckOrders);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:backgroundcheckorders:delete")
    public R delete(@RequestBody Long[] ids) {
        backgroundCheckOrdersService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
